/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modelo.dao;

/**
 *
 * @author Rodrigo
 */

import java.util.List;
import modelo.entidades.*;
import org.hibernate.*;
import org.hibernate.criterion.*;

public class BairroDAO extends GenericDAO<Bairro> {
    
    public List<Bairro> findAll()throws DAOException
    {
        return super.findAll(Bairro.class);      
    }
    
     public Bairro find(Integer id)throws DAOException
    {

        return super.find(id,Bairro.class);      
    }
     
     public List<Bairro> findByFiltro(String regiaoNome, String municipioNome, String bairroNome)
             throws DAOException
     {
         Session session = HibernateUtil.getSessionFactory().openSession();
         
         if(!session.getTransaction().isActive())
             session.beginTransaction(); 
         
         try
         {
         
         Criteria criteria = session.createCriteria(Bairro.class)
                 .add(Restrictions.ilike("nome",bairroNome))
                 .createCriteria("municipio","mun")
                 .add(Restrictions.ilike("mun.nome",municipioNome))
                 .createCriteria("regiao","reg")
                 .add(Restrictions.ilike("reg.nome",regiaoNome));
         
         List<Bairro> lista = criteria.list(); 
         
         return lista; 
         
         }
         catch(Exception e)
         {
             e.printStackTrace();
             throw new DAOException();
         }
         
     }
}
